﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace tester {
    public partial class Form1: Form {


        public delegate void sendSplitImage(string dir);
        public sendSplitImage sendImagesDirectory;

        Font font = new Font(new FontFamily("Microsoft Sans Serif"), 8.25f, FontStyle.Regular);
        Color color = Color.Black;
        string imagePath;

        public Form1() {
            InitializeComponent();

            setFilterString();
            textBox2.Text = @"C:\";

            checkBox1.Enabled = false;
        }

        private void setFilterString()
        {
            string text = "";
            if (checkBoxNumbers.Checked)
                text += FontSplitter.NUMBERS;
            if (checkBoxAZ.Checked)
                text += FontSplitter.LETTERS_UPPERCASE;
            if (checkBoxsmallLetters.Checked)
                text += FontSplitter.LETTERS_LOWERCASE;
            if (checkBoxSpecial.Checked)
                text += FontSplitter.LETTERS_SPECIAL;
            if (checkBoxSymbols.Checked)
                text += FontSplitter.SYMBOLS;

            textBox1.Text = text;
        }

        private void button1_Click(object sender, EventArgs e) {
            if(font != null) {
                FontSplitter.SplitFont(textBox2.Text, font, color, textBox1.Text);
            } 
            else if(imagePath != null) {
                FontSplitter.SplitImage(textBox2.Text, imagePath, textBox1.Text, checkBox1.Checked);
                sendImagesDirectory(textBox2.Text);
                this.DialogResult = System.Windows.Forms.DialogResult.Yes;
                this.Close();
            }
        }

        private void button2_Click(object sender, EventArgs e) {
            FontDialog fd = new FontDialog();
            fd.ShowColor = true;
            fd.ShowEffects = true;

            if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                font = DefaultFont;
                font = fd.Font;
                color = fd.Color;
                imagePath = null;
            }
        }

        private void button3_Click(object sender, EventArgs e) {
            FileDialog fd = new OpenFileDialog();

            if(fd.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                font = null;
                imagePath = fd.FileName;
                checkBox1.Enabled = true;
            }
        }

        private void checkBoxSpecial_CheckStateChanged(object sender, EventArgs e)
        {
            setFilterString();
        }
    }
}